package cn.ncupyh.comptest;

import java.util.Scanner;

//阶乘
public class factorial {
    public static void main(String[] args) {
        //求1！+2！+3！+4！+........+n!的和
        Scanner s = new Scanner(System.in);
        System.out.println("请输入n:");
        int n = s.nextInt();//input
        calculateFactSum(n);//计算阶乘和
        calculateFactor(n);//计算N的阶乘
    }

    private static void calculateFactor(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        System.out.println(n+"的阶乘为:"+ret);
    }

    private static void calculateFactSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(n+"的阶乘和为:"+sum);
    }
}
